#include <stdio.h>
#include <stdlib.h>

typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;

struct TNode {
	ElementType Data;
	BinTree Left;
	BinTree Right;
};


int GetHeight(BinTree BT);

int main() {
	TNode T[20];
	int left, right;
	for (int i = 0; i < 20; i++) {
		T[i].Data = 0;
		T[i].Left = NULL;
		T[i].Right = NULL;
	}
	int n, tempr, templ;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &templ, &tempr);
		if (i == n) {
			left = templ;
			right = tempr;
		}
		if (templ != 0)
			T[i].Left = &T[templ];
		else
			T[i].Left = NULL;
		if (tempr != 0)
			T[i].Right = &T[tempr];
		else
			T[i].Right = NULL;
	}

	printf("%d %d", GetHeight(&T[1]), left);

	return 0;
}

int GetHeight(BinTree BT) {
	int lh, rh;
	if (BT == NULL)
		return 0;
	lh = GetHeight(BT->Left);
	rh = GetHeight(BT->Right);

	return (lh > rh ? lh : rh) + 1;
}